<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>添加商场库</title>
		<link rel="stylesheet" type="text/css" href="/webapp/css/easyui.css">
	    <link rel="stylesheet" type="text/css" href="/webapp/css/icon.css">
        <link rel="stylesheet" type="text/css" href="/webapp/css/color.css">
        <link rel="stylesheet" type="text/css" href="/webapp/css/public.css">
	    <script type="text/javascript" src="/webapp/js/lib/jquery.min.js"></script>
	    <script type="text/javascript" src="/webapp/js/lib/jquery.easyui.min.js"></script>
	    <script type="text/javascript" src="/webapp/js/lib/ajaxfileupload.js"></script>
	    <script type="text/javascript" src="/webapp/js/common/config.js"></script>
	</head>
	<body>
		<div class="easyui-container-fluid">
            <div class="easyui-panel" style="width:100%;border: none;">
                <div class="nav" id="nav">
                    
                </div>
                <div class="easyui-panel">
                	<form id="ff">
                		<div style="margin-bottom:20px;">
                			<label for="" class="item-label">*代码：</label>
                			<input type="text" class="easyui-textbox" name="code" data-options="required:true"/>
                		</div>
                        <div style="margin-bottom:20px;">
                            <label for="" class="item-label" >*名称：</label>
                            <input type="text" class="easyui-textbox" name="name" data-options="required:true"/>
                        </div>
                		<div style="margin-bottom:20px;">
                			<label for="" class="item-label">类型：</label>
                			<select class="easyui-combobox" data-options="panelHeight:'auto'" style="width:174px;" name="type">
                				<option value="PRO_SHOP">家电</option>
                				<option value="SUPERMARKET">超市</option>
                                <option value="DEPARTMENT_STORE">百货</option>
                			</select>
                		</div>
                		<div style="margin-bottom:20px;">
                			<label for="" class="item-label">渠道：</label>
                			<select class="easyui-combobox" data-options="panelHeight:'auto',url:'/webserver/channels/queryall',method:'get',textField:'name',valueField:'code'" style="width:174px;" name="channelCode">
                			</select>
                		</div>
                		<div style="margin-bottom:20px;">
                			<label for="" class="item-label">省市：</label>
                			<select id="province" class="easyui-combobox" data-options="panelHeight:'auto',url:'/webserver/dictionary/getDictionaryByType?type=LOCATION_PROVINCE',method:'get',textField:'name',valueField:'code'" style="width:174px;" name="provinceCode">
                			</select>
                		</div>
                        <div style="margin-bottom:20px;">
                            <label for="" class="item-label">所在市：</label>
                            <select id="city" class="easyui-combobox" data-options="panelHeight:'auto',method:'get',textField:'name',valueField:'id'" style="width:174px;" name="cityCode">
                            </select>
                        </div>
                        <div style="margin-bottom:20px;">
                            <label for="" class="item-label">隶属城市：</label>
                            <select id="belongCity" class="easyui-combobox" data-options="panelHeight:'auto',method:'get',textField:'name',valueField:'id'" style="width:174px;" name="belongCityCode">
                            </select>
                        </div>
                        <div style="margin-bottom:20px;">
                            <label class="item-label">城市区域：</label>
                            <select name="areaCode" class="easyui-combobox" data-options="panelHeight:'auto'" style="width:100px;">
                              <option value="1">东北地区</option>
                              <option value="2">华北地区</option>
                              <option value="3">华东地区</option>
                              <option value="4">华南地区</option>    
                              <option value="5">华中地区</option>
                              <option value="6">西南地区</option>
                              <option value="7">西北地区</option>
                              
                          </select>
                        </div>	
                        <div style="margin-bottom:20px;">
                            <label class="item-label">城市级别：</label>
                            <select class="easyui-combobox" name="cityLevelCode" data-options="panelHeight:'auto'" style="width:170px;">
                              <option value="1">一线城市</option>
                              <option value="2">二线城市</option>
                              <option value="3">三线城市</option>
                              <option value="4">县域城市</option>
                            </select>
                        </div>
                        <div style="margin-bottom:20px;">
                            <label class="item-label">城市规模：</label>
                            <select class="easyui-combobox" name="cityScaleCode" data-options="panelHeight:'auto'" style="width:170px;">
                              <option value="1">超大</option>
                              <option value="2">特大</option>
                              <option value="3">大</option>
                              <option value="4">中</option>
                              <option value="5">小</option>
                              <option value="6">县城</option>
                            </select>
                        </div>
                        <div style="margin-bottom:20px;">
                            <label class="item-label">南方北方：</label>
                            <select class="easyui-combobox" name="northern" data-options="panelHeight:'auto'" style="width:170px;">
                              <option value="true">北方</option>
                              <option value="false">南方</option>         
                            </select>
                        </div>
                		<div style="margin-bottom:20px;">
                			<label for="" class="item-label">备注：</label>
                			<input type="text" class="easyui-textbox" multiline="true" data-options="" style="width:440px;height:120px;" name="remark"/>
                		</div>
                        <div style="margin-bottom:20px;margin-left:100px;">
                            <a href="javascript:void(0);" class="easyui-linkbutton c8" style="width:80px" onclick="submitForm()">保存</a>
                            <a href="javascript:void(0);" class="easyui-linkbutton" style="width:80px;" onclick="clearForm()">取消</a>
                        </div>
                	</form>
                </div>
            </div>
	</body>
    <script type="text/javascript">
        var id = getQueryParameter("id");
        $(function(){
            setNav();
            if(id){
                $.ajax({
                  url:config.url +"/mall",
                  type:'get',
                  data:{id:id},
                  xhrFields:{withCredentials:true},
                  success:function(data){
                    //填充表单
                      if(data){
                          $("#ff").form("load",changeProperty2String(data.content[0]));
                          $("#code").textbox("textbox").attr("readonly",true);
                      }   
                  },
                  error:function(){

                  }
                });
            }
            $("#province").combobox({
                onChange:function(newValue,oldValue){
                    console.log(newValue);
                    $("#city").combobox({
                        url:config.url+'/dictionary/getDictionaryByType?type=LOCATION_CITY'
                    })
                }
            });
        });
        function submitForm(){
            $("#ff").form("submit",{
               onSubmit:function(){
                  var valid = $(this).form('enableValidation').form('validate');
                  if(valid){
                      var mall = getFormData(document.getElementById("ff"));
                      mall.cityCode="11000";
                      mall.belongCityCode="11000";
                      var method = "POST";
                        if(id){
                          method = "PATCH";
                          mall.id = id;
                        }
                      $.ajax({
                         url:config.url+"/mall",
                         type:method,
                         data:JSON.stringify(mall),
                         dataType:'json',
                         contentType:'application/json;charset=UTF-8',
                         beforeSend:function(){
                            window.parent.window.load();
                         },
                         complete:function(){
                            window.parent.window.disLoad();
                         },
                         xhrFields:{withCredentials:true},
                          success:function(data){
                              //if(data){
                              $.messager.alert("提示","操作成功","info",function(){
                                 window.location.href = "./list.html";
                              });
                              //}
                          },
                          error(XMLHttpRequest,textStatus,thrown){

                          }
                      });
                       return false;
                    }
                    return false;
                  
               }
          });
        }
        function clearForm(){
            $("#ff").form("reset");
        }
    </script>
</html>